// 表单提交
function commit() {
    if ($('#old_pwd').val() == "" ){
        $('#label_psw').css("display","inline-block");
        $('#span_old_tag').css("display","none");
        return;
    }else if($('#old_pwd').val().length<6) {
        $('#label_psw').css("display","inline-block");
        $('#label_psw').html("请输入最少六位数密码");
        $('#span_old_tag').css("display","none");
        return;
    }else {
        $('#label_psw').css("display","none");
        $('#span_old_tag').css("display","inline-block");
        // return;
    }

    if ($('#new_pwd').val() == "" ){
        $('#label_new_psw').css("display","inline-block");
        $('#label_new_psw').html("密码不能为空");
        $('#span_new_tag').css("display","none");
        return;
    }else if($('#new_pwd').val().length<6) {
        $('#label_new_psw').css("display","inline-block");
        $('#label_new_psw').html("请输入最少六位数密码");
        $('#span_new_tag').css("display","none");
        return;
    }else {
        $('#label_new_psw').css("display","none");
        $('#span_new_tag').css("display","inline-block");
        // return;
    }

    if ($('#confirm_pwd').val() == "" ){
        $('#label_new_psw_confirm').css("display","inline-block");
        $('#label_new_psw_confirm').html("密码不能为空");
        $('#span_confirm_tag').css("display","none");
        return;
    }else if($('#confirm_pwd').val().length<6) {
        $('#label_new_psw_confirm').css("display","inline-block");
        $('#label_new_psw_confirm').html("请输入最少六位数密码");
        $('#span_confirm_tag').css("display","none");
        return;
    }else {
        $('#label_new_psw_confirm').css("display","none");
        $('#span_confirm_tag').css("display","inline-block");
    }

    if ($('#confirm_pwd').val() === $('#new_pwd').val()) {

        $('#label_new_psw_confirm').css("display","none");
        $('#label_new_psw').css("display","none");

        $('#span_old_tag').css("display","inline-block");
        $('#span_new_tag').css("display","inline-block");
        $('#span_confirm_tag').css("display","inline-block");

        var oldPwd = $('#old_pwd').val();
        var newPwd = $('#confirm_pwd').val();
        $.ajax({
            url: basePath + "/user/updatePassword",
            data: {
                "oldPassword": $.md5(oldPwd),
                "newPassword": $.md5(newPwd)
            },
            //数据，这里使用的是Json格式进行传输
            dataType: "json",
            type: "post",
            contentType: "application/x-www-form-urlencoded",
            beforeSend: null,
            success: function (data) {
                if (data.status == 1) {
                    $.wdfProgress.progress("系统即将退出,请重新登录",$("body"), true);
                    // 表单清空
                    $('#old_pwd').val("");
                    $('#new_pwd').val("");
                    $('#confirm_pwd').val("");

                    setTimeout(function() {
                        $.ajax({
                            url:basePath+"/system/logout",
                            //processData: false,
                            //data: xmlDocument,
                            async:true,
                            dataType:"json",
                            type: "POST",
                            contentType:"application/x-www-form-urlencoded",
                            beforeSend:null,
                            success:function(data){
                                if (data.status == 1) {
                                    window.parent.location.href=basePath+formateUrl("imp/system/login/login");
                                }
                            },
                            error:function (XMLHttpRequest, textStatus, errorThrown) {
                                $.wdfProgress.showMsg("服务器异常或网络超时！",$("body"),true);
                            }
                        });
                    }, 1000);

                } else {
                    $('#span_old_tag').css("display","none");
                    $('#label_psw').css("display","inline-block");
                    $('#label_psw').html(data.msg.replace("操作失败,原因为:", ""));
                    $('#old_pwd').val("");
                    $('#new_pwd').val("");
                    $('#confirm_pwd').val("");
                }
            }
        });
    } else {
        // $('#span_new_tag').css("display","none");
        // $('#span_confirm_tag').css("display","none");
        $('#label_new_psw_confirm').html("两次密码不一致");
        $('#label_new_psw').html("两次密码不一致");
        $('#label_new_psw_confirm').css("display","inline-block");
        $('#label_new_psw').css("display","inline-block");
    }

}

// 表单重置
function reset() {
    $('#old_pwd').val("");
    $('#new_pwd').val("");
    $('#confirm_pwd').val("");
    $('#label_psw').css("display", "none");
    $('#label_new_psw').css("display", "none");
    $('#label_new_psw_confirm').css("display", "none");
    $('#label_new_psw_confirm').css("display","none");
    $('#label_new_psw').css("display","none");
}

function Referesh() {
    $.ajax({
        url:basePath+"gzmli/user/getCurrentUser",
        //processData: false,
        //data: xmlDocument,
        dataType:"json",
        type: "post",
        contentType:"application/x-www-form-urlencoded",
        beforeSend:null,
        success:function(data){

            data = data.data;
            var userInfo = data;

            $("#ipt_name").attr("placeholder",userInfo.name);
            $('#label_name', window.parent.document).text("你好，"+userInfo.name);

            // $("#the_userName").html(userInfo.userName);
            $("#ipt_dpartment").attr("placeholder",userInfo.department.name);
            var sex;
            if(userInfo.sex == UserInfoSex_1_Man){ 
                sex = "男";
            }else{
                sex = "女";
            }
            if(sex==""||sex==null){
                $("#ipt_sex").attr("placeholder","无");
            }else {
                $("#ipt_sex").attr("placeholder",sex);
            }
            if(userInfo.email==""||userInfo.email==null){
                $("#ipt_email").attr("placeholder","无");
            }else {
                $("#ipt_email").attr("placeholder",userInfo.email);
            }
            if(userInfo.phone==""||userInfo.phone==null){
                $("#ipt_tel").attr("placeholder","无");
            }else {
                $("#ipt_tel").attr("placeholder",userInfo.phone);
            }
            //
            if(userInfo.headerpath==""||userInfo.headerpath==null){
            }else {
                $("#img_head", window.parent.document).attr("src",basePath+"/upload/100/"+userInfo.headerpath);
                $("#img_head").attr("src",basePath+"/upload/100/"+userInfo.headerpath);
                $("#head_user_header", window.parent.document).attr("src",basePath+"/upload/100/"+userInfo.headerpath);
            }


        },
        error: function (data) {
            $.wdfProgress.progress("上传失败",$("body", window.parent.parent.document));

            setTimeout("$(\"#undefined_wdfProgress_Bg\",window.parent.parent.document).hide()",1000);
            setTimeout("$(\"#undefined_wdfProgress_Prog\",window.parent.parent.document).hide()",1000);
        }});
}